﻿Public Class Plainte
    Public Id As Integer
    Public Num_Plainte As Integer
    Public Annee As Integer
    Public Type As String
    Public Nom_wakil As String
    Public Date_Inscreption As String
    Public Objecte As String
    Public Tribunal As String
    Public Observ As String
    Public dicision As String

    Public list_hifde As New List(Of Hifde)
    Public list_Plainte_Ref As New List(Of Plainte_Ref)
    Public list_Plainte_envoi As New List(Of Plainte_Envoi)

    Public Sub New()

    End Sub

    Public Sub New(ByVal id As Integer, ByVal num As Integer, ByVal annee As Integer, ByVal type As String, ByVal wakil As String, ByVal dat As String, ByVal obj As String, ByVal tri As String, ByVal ob As String, ByVal dis As String)
        Me.Id = id
        Me.Num_Plainte = num
        Me.Annee = annee
        Me.Type = type
        Me.Nom_wakil = wakil
        Me.Date_Inscreption = dat
        Me.Objecte = obj
        Me.Tribunal = tri
        Me.Observ = ob
        Me.dicision = dis
    End Sub

    Sub New(ByVal enregistrement As ArrayList)
        Me.Id = enregistrement.Item(0)
        Me.Num_Plainte = enregistrement.Item(1)
        Me.Annee = enregistrement.Item(2)
        Me.Type = enregistrement.Item(3)
        If enregistrement.Item(4) = "01/01/1900" Then
            Me.Date_Inscreption = ""
        Else
            Me.Date_Inscreption = enregistrement.Item(4)
        End If
        Me.Nom_wakil = enregistrement.Item(5)
        Me.Objecte = enregistrement.Item(6)
        Me.Tribunal = enregistrement.Item(7)
        Me.Observ = enregistrement.Item(8)
        Me.dicision = enregistrement.Item(9)
    End Sub


    '------------------Les methode de la classe hifde----------------------
    Public Sub remplir_List_hifde()
        Me.list_hifde.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from Hifde where Id_Plainte =" & Me.Id, Partager.con)
        Dim str As String
        Partager.open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Str = ""
            If Partager.dr("Date_Hifd") = "01/01/1900" Then
                Str = ""
            Else
                Str = Partager.dr("Date_Hifd")
            End If
            Dim hfd As New Hifde(Partager.dr("Id_Plainte"), Str)
            Me.list_hifde.Add(hfd)
        End While
        Partager.dr.Close()
        Partager.close()
    End Sub

    Public Sub suprimmer_hifde()

        Dim cmd As New SqlClient.SqlCommand("delete FROM  Hifde where Id_Plainte=" & Me.Id, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_hifde()
    End Sub

    Public Sub Ajouter_hifde(ByVal hfd As Hifde)

        Dim cmd As New SqlClient.SqlCommand("insert into Hifde values(" & Me.Id & ",'" & hfd.Date_Hifd & "')", Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_List_hifde()
    End Sub

    '------------------Les methode de la classe Plainte_Ref----------------------
    Public Sub remplir_Plainte_Ref()
        Me.list_Plainte_Ref.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from Plainte_ref where id_plainte =" & Me.Id, Partager.con)
        Partager.open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Dim plnt As New Plainte_Ref(Partager.dr("id_plainte"), Partager.dr("ref"), Partager.dr("sifa_enemi"), Partager.dr("sifa_client"))
            Me.list_Plainte_Ref.Add(plnt)
        End While
        Partager.dr.Close()
        Partager.close()
    End Sub

    Public Sub suprimmer_Plainte_Ref()

        Dim cmd As New SqlClient.SqlCommand("delete FROM  Plainte_ref where Id_Plainte=" & Me.Id, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_Plainte_Ref()
    End Sub

    Public Sub Ajouter_Plainte_Ref(ByVal plnt As Plainte_Ref)

        Dim cmd As New SqlClient.SqlCommand("insert into Plainte_ref values(" & Me.Id & ",@ref,@sifa_enemi,@sifa_client)", Partager.con)

        cmd.Parameters.Add("@ref", SqlDbType.Int).Value = plnt.ref
        cmd.Parameters.Add("@sifa_enemi", SqlDbType.VarChar).Value = plnt.sifa_enemi
        cmd.Parameters.Add("@sifa_client", SqlDbType.VarChar).Value = plnt.sifa_client
        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_Plainte_Ref()
    End Sub
    '------------------Les methode de la classe Plainte_envoi----------------------
    Public Sub remplir_Plainte_envoi()
        Me.list_Plainte_envoi.Clear()
        Dim cmd As New SqlClient.SqlCommand("select * from Envoi_Planite where id_plainte =" & Me.Id, Partager.con)
        Partager.open()
        Partager.dr = cmd.ExecuteReader
        While Partager.dr.Read
            Dim plnt As New Plainte_Envoi(Partager.dr("id_plainte"), Partager.dr("Id_Envoi"))
            Me.list_Plainte_envoi.Add(plnt)
        End While
        Partager.dr.Close()
        Partager.close()
    End Sub

    Public Sub suprimmer_Plainte_envoi()

        Dim cmd As New SqlClient.SqlCommand("delete FROM  Envoi_Planite where Id_Plainte=" & Me.Id, Partager.con)

        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_Plainte_envoi()
    End Sub

    Public Sub Ajouter_Plainte_envoi(ByVal plnt As Plainte_Envoi)

        Dim cmd As New SqlClient.SqlCommand("insert into Envoi_Planite values(" & plnt.id_envoi & "," & plnt.id_plainte & ")", Partager.con)
        Partager.open()
        cmd.ExecuteNonQuery()
        Partager.close()

        Me.remplir_Plainte_envoi()
    End Sub

    
End Class
